package com.ziqing.apeletnews.login.prenstener;

import android.content.Context;

import com.blankj.utilcode.utils.LogUtils;
import com.ziqing.apeletnews.base.BaseActivity;
import com.ziqing.apeletnews.baseMvp.BasePresenter;
import com.ziqing.apeletnews.bean.UserModel;
import com.ziqing.apeletnews.login.contact.LoginContact;
import com.ziqing.apeletnews.retrofit.ProgressObserver;
import com.ziqing.apeletnews.retrofit.RetrofitManger;
import com.ziqing.apeletnews.retrofit.RetrofitUtil;

import io.reactivex.Observable;

/**
 * Created by abc on 2018-04-28.
 */

public class LoginPresenter extends BasePresenter<LoginContact.LoginView> implements LoginContact.presenter {

    private BaseActivity activity;
    public LoginPresenter(BaseActivity activity){
        this.activity=activity;
    }
    /**
     * 重写P层需要的生命周期，进行相关逻辑操作
     */

    @Override
    public void login() {
        Observable dologin = RetrofitManger.getDefault().doLogin("18158653013", "123456");
        RetrofitUtil.getInstance().toSubscribe(dologin, new ProgressObserver<UserModel>(activity) {
            @Override
            protected void _onNext(UserModel o) {
                getView().loginSuccess(o.getNickname());
            }


            @Override
            protected void _onError(String message) {
                LogUtils.d(message);
            }
        }, "doLogin",activity.bindToLifecycle(), true);
    }

}

